define(function (require, exports, module) {

    require("apps/grid");
    require("apps/easyui");

    exports.init = function (ctx, uuid) {
        var page = new $.PageDomFactory(uuid);
        var contextWindow = new $.PageWindow();

        var pageComponentList = new $.PageListComponent(uuid, {
            view: {
                grid: "grid",
                myToolbar: "nsdb",
                colbar: "template"
            },
            configs: {
                gridTitle: "日志打包列表",
                gridUrl: ctx + '/app/api/logPackage/queryPageForJson',
                gridColumns: [
                    {
                        field: 'id',
                        checkbox: true
                    },
                    {
                        field: 'temp1',
                        hidden: true
                    },
                    {
                        field: 'packageName',
                        title: '包名称',
                        width: 200,
                        align: 'left'
                    },
                    {
                        field: 'itemsNum',
                        title: '日志数量',
                        width: 100,
                        align: 'left'
                    },

                    {
                        field: 'createDate',
                        title: '打包时间',
                        width: 150,
                        align: 'left',
                        formatter: function (value, rowData, rowIndex) {
                            return value ? new Date(value).format("yyyy-MM-dd hh:mm:ss") : "<a>NA</a>"
                        }
                    }
                ]
            },
            events: {
                renderColBarBefore: function () {
                    return true;
                },
                onClickColBtn: function (context, btn, row) {
                    switch (btn.key) {
                        case "download":
                            whenDownload(context, row);
                            break;
                        default :
                            break;
                    }
                },
                onClickToolbarBtn: function (context, btn) {
                    switch (btn.key) {
                        case "del":
                            context.del(btn.href);
                            break;
                        case "search_all":
                            context.searchAll();
                            break;
                        case "search":
                            context.search(btn.href, "打包搜索", "log_package_search");
                            break;
                        default :
                            break;
                    }
                }
            }
        });

        function whenDownload(context, row) {
            window.location.href = "/download/" + row.logFile;
        }
    };
    exports.search = function(ctx, uuid){
        var page = new $.PageDomFactory(uuid, true);
        window.log_package_search = function(win) {
            win.wait("start", "搜索中,请稍候.");
            var form = page.getJqDom("form-org-search-info");
            var postData = form.serializeJson();
            win.callback(postData);
            win.close();
        }
    }
});